home *** CD-ROM | disk | FTP | other *** search
/ AppleScript - The Beta Release / AppleScript - The Beta Release.iso / Documentation / develop / Better Apple Event Coding / Code Samples / TEDocument.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-16  |  4.6 KB  |  156 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------------------
  2.  
  3.     Program:    CPlusTESample 2.0
  4.     File:        TEDocument.h
  5.     Uses:       Document.h
  6.  
  7.     by Andrew Shebanow
  8.     of Apple Macintosh Developer Technical Support
  9.     with modifications by Eric Berdahl
  10.  
  11.     Copyright © 1989-1990 Apple Computer, Inc.
  12.     Copyright © 1992 Eric Berdahl
  13.     All rights reserved.
  14.  
  15. ------------------------------------------------------------------------------------------*/
  16.  
  17. #ifndef __TEDOCUMENT__
  18. #define __TEDOCUMENT__
  19.  
  20. #ifndef __TYPES__
  21. #include <Types.h>
  22. #endif
  23. #ifndef __TEXTEDIT__
  24. #include <TextEdit.h>
  25. #endif
  26. #ifndef __CONTROLS__
  27. #include <Controls.h>
  28. #endif
  29. #ifndef __EVENTS__
  30. #include <Events.h>
  31. #endif
  32.  
  33. #ifndef __DOCUMENT__
  34. #include "Document.h"
  35. #endif
  36.  
  37. #ifndef    _UAPPLEOBJECT_
  38. #include "UAppleObject.h"
  39. #endif
  40.  
  41. // kTEFileType is the type of our files - in this case, TEXT
  42. const OSType kTEFileType = 'TEXT';
  43.  
  44.  
  45. class TEDocument : public TDocument, public MAppleObject {
  46. private:
  47.     Boolean            fSelFontContinuous;        // does the selection have a continous style
  48.     Boolean            fSelFaceContinuous;
  49.     Boolean            fSelSizeContinuous;
  50.     TextStyle        fTxStyle;                // the style of the selection text
  51.     TEHandle        fDocTE;                    // our text
  52.     ControlHandle    fDocVScroll;            // vertical scrollbar
  53.     ControlHandle    fDocHScroll;            // horizontal scrollbar
  54.     ClikLoopProcPtr    fDocClik;                // our clik loop
  55.  
  56. public:
  57.     // methods not intended for use outside of this class
  58.     // They aren't virtual since private routines can
  59.     // never be overridden, and non-virtual calls are
  60.     // faster than virtual calls.
  61.     // EMB Note: except for the fact that scriptability requires that some
  62.     //           of them are callable from the scripting temp classes
  63.             void    GetTERect(Rect* teRect);
  64.             void    AdjustTE();
  65.             void    DrawWindow();
  66.             void    AdjustViewRect();
  67.             void    ResizeWindow();
  68.             void    AdjustHV(Boolean isVert,Boolean mustRedraw);
  69.             void    AdjustScrollSizes();
  70.             void    AdjustScrollbars(Boolean needsResize);
  71.  
  72. private:
  73.     static pascal void    VActionProc(ControlHandle control,short part);
  74.     static pascal void    HActionProc(ControlHandle control,short part);
  75.  
  76.     // Object Model support
  77.     virtual DescType GetAppleClass() const;
  78.     virtual long CountContainedObjects(DescType ofType);
  79.     virtual void DoAppleEvent(const AppleEvent& message,
  80.                               AppleEvent& reply,
  81.                               long refCon);
  82.     virtual MAppleObject* GetContainedObject(DescType desiredType,
  83.                                              DescType keyForm,
  84.                                              const AEDesc& keyData,
  85.                                              Boolean& needDisposal);
  86.     virtual Boolean CompareAppleObjects(DescType operation,
  87.                                         const MAppleObject& toWhat);
  88.  
  89.     // Methods to implement the AppleEvent protocols
  90.     virtual void DoAppleSave(const AppleEvent& message, AppleEvent& reply);
  91.     virtual void DoAppleClose(const AppleEvent& message, AppleEvent& reply);
  92.  
  93.     virtual MAppleObject* GetAppleProperty(DescType keyFrom, const AEDesc& keyData,
  94.                                            Boolean& needDisposal);
  95. protected:
  96.     // i/o routines
  97.     virtual void    ReadFromFile(short refNum);
  98.     virtual void    WriteToFile(short refNum);
  99.  
  100.     TEHandle        GetTEHandle();
  101. public:
  102.                     TEDocument(short resID);
  103.     virtual            ~TEDocument();
  104.  
  105.     // methods from TDocument we override
  106.     virtual void    DoZoom(short partCode);
  107.     virtual void    DoGrow(EventRecord* theEvent);
  108.     virtual void    DoContent(EventRecord* theEvent);
  109.     virtual void    DoKeyDown(EventRecord* theEvent);
  110.     virtual void    DoActivate(Boolean becomingActive);
  111.     virtual void    DoIdle();
  112.     virtual void    DoUpdate();
  113.     virtual void    DoCut();
  114.     virtual void    DoCopy();
  115.     virtual void    DoPaste();
  116.     virtual void    DoClear();
  117.     virtual unsigned long CalcIdle();
  118.     virtual Boolean    HaveSelection();
  119.     virtual void    DoSelectAll();
  120.  
  121.     // methods added to support changing text attributes
  122.     virtual void    SetFontName(Str255 fontName);
  123.     virtual void    SetFont(short fontID);
  124.     virtual void    SetFontSize(short fontSize);
  125.  
  126.     virtual short    GetSelectionFontSize();
  127.     virtual short    GetSelectionFont();
  128.  
  129.     virtual Boolean    SelectionIsPlain();
  130.     virtual Boolean    SelectionIsBold();
  131.     virtual Boolean    SelectionIsItalic();
  132.     virtual Boolean    SelectionIsUnderline();
  133.     virtual Boolean    SelectionIsOutline();
  134.     virtual Boolean    SelectionIsShadow();
  135.  
  136.     virtual void    SetPlain();
  137.     virtual void    SetBold(Boolean on = true);
  138.     virtual void    SetItalic(Boolean on = true);
  139.     virtual void    SetUnderline(Boolean on = true);
  140.     virtual void    SetOutline(Boolean on = true);
  141.     virtual void    SetShadow(Boolean on = true);
  142.  
  143.     // new public methods
  144.     void            AdjustScrollValues(Boolean mustRedraw);
  145.     ClikLoopProcPtr GetClikLoop();
  146.     void            GetVisTERgn(RgnHandle rgn);
  147.  
  148.     // base TextEdit accessor functions
  149.     virtual void    SetFaceAttributes(short attributes, Boolean on = true);
  150.     virtual Boolean    GetFaceAttributes(short attributes);
  151.  
  152.     virtual void    UpdateForNewSelection();
  153. };
  154.  
  155. #endif
  156.